let registerBtn = document.querySelector(".register-btn");
function dosubmit() {
  let registerE = document.querySelector(".register-email").value;
  let registerPwd = document.querySelector(".register-password").value;
  let surePwd = document.querySelector(".surePassword").value;
  let code = document.querySelector(".register-code").value;
  let reg =
    /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  // 清除空格后的
  let afterPwd = registerPwd.trim().split(" ").join("").length;

  if (registerE == "" || registerPwd == "") {
    showCustomAlert("密码或邮箱不能为空", false);
    return false;
  } else if (!reg.test(registerE)) {
    showCustomAlert("邮箱格式错误");
    return false;
  } else if (surePwd == "") {
    showCustomAlert("请确认密码！", false);
    return false;
  } else if (code.length < 6) {
    showCustomAlert("验证码格式错误（不应小于6位）");
    return false;
  } else if (afterPwd != registerPwd.length) {
    showCustomAlert("密码不能包含空格");
    return false;
  } else if (code == "") {
    showCustomAlert("请输入验证码");
    return false;
  } else if (surePwd != registerPwd) {
    showCustomAlert("两次密码不一致，请重新输入！");
    return false;
  } else {
    return true;
  }
}

// registerBtn.onclick=function (){
//   let registerE = document.querySelector(".register-email").value;
// let registerPwd = document.querySelector(".register-password").value;
//   let surePwd = document.querySelector(".surePassword").value;
//   let code = document.querySelector(".register-code").value;
//   if (registerE == "" || registerPwd == "") {
//     showCustomAlert("密码或邮箱不能为空", false);
//     return;
//   }else if (surePwd == "") {
//    showCustomAlert("请确认密码！", false);
// return;
//   }else if(surePwd!=registerPwd){
//     showCustomAlert("两次密码不一致，请重新输入！");
// return;
//   }else if(code==""){
//     showCustomAlert("请输入验证码");
// return;
//   }
//   $.ajax({
//     url:"/weibo/user/register",
//     type:'post',
//     data:{
//       email:registerE,
//       password:registerPwd,
//       code:code,
//     },
//     success:function (msg){
//       showCustomAlert("cheggong")
//       console.log(msg)
//     },
//     error:function (msg){
//       console.log(msg)
//     }
//   })
// }

// 验证码部分功能
var codeBtn = document.querySelector(".code");

let count = localStorage.getItem("count") || 60;
function settime() {
  localStorage.setItem("count", count);
  if (count <= 0) {
    codeBtn.style.pointerEvents = "auto";
    count = 60;
    codeBtn.innerHTML = "发送验证码";
    localStorage.removeItem("count");
    return;
  } else if (count > 0) {
    codeBtn.style.pointerEvents = "none";
    codeBtn.innerHTML = count + "s重新发送";
    count--;
  }
  setTimeout(function () {
    settime();
  }, 1000);
}

if (localStorage.getItem("count") > 0) {
  console.log(111);
  settime();
}

codeBtn.onclick = function () {
  let registerE = document.querySelector(".register-email").value;
  if (registerE == "") {
    return showCustomAlert("邮箱不能为空");
  }
  $.ajax({
    url: "/weibo/user/getCode",
    type: "post",
    data: {
      email: registerE,
    },
    success: function (result) {
      settime();
      showCustomAlert("发送成功", true);
    },
    error: function (error) {
      showCustomAlert("发送失败");
    },
  });
};
let flag = 0;
var eye = document.querySelector(".iconfont");
eye.onclick = function () {
  let password = document.querySelector(".register-password");
  if (flag == 0) {
    password.type = "text";
    eye.innerHTML = "&#xe715;";
    flag = 1;
  } else {
    password.type = "password";
    eye.innerHTML = "&#xe714;";
    flag = 0;
  }
};
